package StudentSys;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

@WebServlet("/Stuserlert")
public class Stuserlert extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String chengji = req.getParameter("chengji");
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("C:\\Users\\Admin\\Desktop\\1.txt", true));
        bufferedWriter.write(name+","+age+","+chengji);
        bufferedWriter.newLine();
        bufferedWriter.flush();
        bufferedWriter.close();
        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write("添加成功。2秒后跳转到首页。。。");
        resp.setHeader("Refresh","2;stu.html");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
